package com.tdkj.service.common.impl;

import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tdkj.dao.common.IBeanFileDao;
import com.tdkj.dao.common.IBeanPhotoCategoryDao;
import com.tdkj.model.base.BaseEntity;
import com.tdkj.model.common.BeanFile;
import com.tdkj.model.common.BeanPhotoCategory;
import com.tdkj.service.BaseService;
import com.tdkj.service.common.IBeanPhotoCategoryService;
import com.tdkj.util.FileUtil;
@Component("beanPhotoCategoryService")
public class BeanPhotoCategoryServiceImpl extends BaseService implements IBeanPhotoCategoryService{
	private  IBeanPhotoCategoryDao beanPhotoCategoryDao;
	private IBeanFileDao fileDao;

	public IBeanPhotoCategoryDao getBeanPhotoCategoryDao() {
		return beanPhotoCategoryDao;
	}
	@Resource
	public void setBeanPhotoCategoryDao(IBeanPhotoCategoryDao beanPhotoCategoryDao) {
		this.beanPhotoCategoryDao = beanPhotoCategoryDao;
	}
	public IBeanFileDao getFileDao() {
		return fileDao;
	}
	@Resource
	public void setFileDao(IBeanFileDao fileDao) {
		this.fileDao = fileDao;
	}

	@Override
	public void deletePhoto(Long id,String path) throws Exception {
		// TODO Auto-generated method stub
		BeanFile f=this.findById(id,BeanFile.class);
		String url=f.getUrl();
		FileUtil.deleteFile(path+"/"+url);
		fileDao.delete(id, BeanFile.class);
	}

	@Override
	public void savePhoto(Long id, BeanFile bean) {
		// TODO Auto-generated method stub
		BeanPhotoCategory c=beanPhotoCategoryDao.findById(id, BeanPhotoCategory.class);
		c.getPhotos().add(bean);
		this.saveOrUpdate(c, BeanPhotoCategory.class);
	}
	@Override
	public BeanFile findFileByUUID(String uuid) {
		// TODO Auto-generated method stub
		BeanFile f=new BeanFile();
		f.setUuid(uuid);
		List<BeanFile> l=fileDao.findByExample(f);
		if(l.size()>=1){
			return l.get(0);
		}else{
			return null;
		}
	}
}
